package ans.p205;

import test.Entrance;

import java.util.HashMap;
import java.util.Map;

/**
 * #      205
 * 名称   同构字符串
 * 链接   https://leetcode-cn.com/problems/isomorphic-strings
 * 题解   [704](https://leetcode-cn.com/problems/isomorphic-strings/solution)
 * 通过率 49.9%
 * 难道   简单
 */

public class Solution {
    @Entrance
    public boolean isIsomorphic(String s, String t) {

        Map<Character, Character> map1 = new HashMap<>(s.length() + t.length());
        Map<Character, Character> map2 = new HashMap<>(s.length() + t.length());
        for (int i = 0; i < s.length(); i++) {
            Character c1 = s.charAt(i);
            Character c2 = t.charAt(i);
            Character character1 = map1.get(c1);
            Character character2 = map2.get(c2);
            if (character1 == null && character2 == null) {
                map1.put(c1, c2);
                map2.put(c2, c1);
            } else if (character1 != c2 || character2 != c1) {
                return false;
            }
        }
        return true;

    }
}